
package teehee.UI;

//import teehee.UI.AddNewWOD.ButtonClickHandler;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import teehee.Form.SubmitInfoForm;
import teehee.Manager.SubmitInfoManager;
import teehee.homepage.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
//import android.widget.TextView;
import android.widget.Toast;

/**
 * @author Bohan Liu
 *
 */

public class SubmitInfo extends Activity {
	public static boolean fromSubmit;
	public void onCreate(Bundle savedInstanceState) {
	    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.weight);
        fromSubmit = true;
	}
	
	public void submitInfo(View view) {
	    Intent intent_one = new Intent(SubmitInfo.this, HealthHistory.class);
	    
	    
	    EditText curWeight = (EditText) findViewById(R.id.editText3);
	    String weight = curWeight.getText().toString().trim();
	    intent_one.putExtra("weightnum", weight);
	    
	    //EditText curHeight = (EditText) findViewById(R.id.editText4);
	    String height = "183";//curHeight.getText().toString();
	    intent_one.putExtra("heightnum", height);
	    
	    //String heightText = height;
	    //curHeight.setText(heightText, TextView.BufferType.EDITABLE);
	    
	    //EditText curDate = (EditText) findViewById(R.id.editText5);
	    //String date = curDate.getText().toString();
    	Calendar c = Calendar.getInstance();
    	SimpleDateFormat f1 = new SimpleDateFormat("MM-dd-yyyy");
	    String date = f1.format(c.getTime());
	    intent_one.putExtra("datenum", date);	    
	    

        

       // boolean isWeight = SubmitInfoForm.validWeight(weight);

        boolean isWeight = SubmitInfoForm.valid(weight);

        //boolean isHeight = form.validHeight(height);


        //boolean isDate = form.validDate(date);
      
        

    	/*TextView errorMsg1 = (TextView) findViewById(R.id.invalidWeight);
 	    TextView errorMsg2 = (TextView) findViewById(R.id.invalidHeight);	    */
 	    //TextView errorMsg3 = (TextView) findViewById(R.id.invalidDate);	  
 	    
        if (isWeight == true) {
        	Context ctx = getApplicationContext();
        	SubmitInfoManager.addWeight(ctx, weight);
	        startActivity(intent_one);
	    }
        else 
        {


       if(isWeight != true)
       {


        		Context context = getApplicationContext();
				CharSequence text = "Invalid Input. Only numbers allowed! ";
				int duration = Toast.LENGTH_SHORT;

				Toast toast = Toast.makeText(context, text, duration);
				toast.setGravity(Gravity.TOP|Gravity.LEFT, 25, 300);
				toast.show();
        	
        	
        }
        //curWeight.setText(null);
        //curHeight.setText(null);
        
	}
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if ((keyCode == KeyEvent.KEYCODE_SEARCH)) //replace "MENU" with "SEARCH" to use the search button
        { 
        	//setContentView(R.layout.search); //xml file to display, found in res/layout
        	Intent homep = new Intent(SubmitInfo.this, SearchPage.class); //XXX.this is the current page. YYY.class is the destination page.
    		startActivity(homep);
            return true;
        }
        
        if ((keyCode == KeyEvent.KEYCODE_MENU)) //replace "MENU" with "SEARCH" to use the search button
        { 
        	//setContentView(R.layout.search); //xml file to display, found in res/layout
        	Intent homep = new Intent(SubmitInfo.this, MainPage.class); //XXX.this is the current page. YYY.class is the destination page.
    		startActivity(homep);
            return true;
        }
        return super.onKeyDown(keyCode, event);    
    } 
	
}



